package cn.glenn._06interceptor.base.config;

import cn.glenn._06interceptor.base.interceptors.MyInterceptor1;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 实现WebMvcConfigurer接口 Spring MVC的标准化配置接口
 */
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //注册拦截器并添加拦截路径
        //策略一拦截所有路径
//        registry.addInterceptor(new MyInterceptor1()).addPathPatterns("/v1/**");
        //策略二：拦截指定的多个请求，比如拦截注册和登录
//        registry.addInterceptor(new MyInterceptor1()).addPathPatterns("/v1/user/reg","/v1/user/changePwd");
        //策略三：排除指定的请求，比如：拦截用户模块中除了注册之外的所有请求
        registry.addInterceptor(new MyInterceptor1())
                .addPathPatterns("/v1/user/**")
                .excludePathPatterns("/v1/user/reg");
    }
}
